package com.liang.design;

import com.liang.design.event.EventManager;
import com.liang.design.event.listener.MQEventListener;
import com.liang.design.event.listener.MessageEventListener;

/**
 * @author lsm
 * @ClassName LotteryService.java
 * @Description TODO
 * @createTime 2023年12月05日 20:22:00
 */
public abstract class LotteryService {

    private EventManager eventManager;
    public LotteryService() {
        eventManager = new EventManager(EventManager.EventType.MQ, EventManager.EventType.Message);
        eventManager.subscribe(EventManager.EventType.MQ, new MQEventListener());
        eventManager.subscribe(EventManager.EventType.Message, new MessageEventListener());
    }
    public LotteryResult draw(String uId) {
        LotteryResult lotteryResult = doDraw(uId);
        // 需要什什么通知就给调⽤用什什么⽅方法
        eventManager.notify(EventManager.EventType.MQ, lotteryResult);
        eventManager.notify(EventManager.EventType.Message, lotteryResult);
        return lotteryResult;
    }
    protected abstract LotteryResult doDraw(String uId);
}
